<template>
  <div>
  <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column
      prop="time"
      label="购买时间"
      width="210"
      align="center">
    </el-table-column>
    <el-table-column label="购物信息"  align="center">
      <el-table-column
        prop="oid"
        label="订单编号"
        width="210"
        align="center">
      </el-table-column>
      <el-table-column label="药物信息"
                       align="center">
        <el-table-column
          prop="oname"
          label="药物名称"
          width="210"
          align="center">
        </el-table-column>
        <el-table-column
          prop="sl"
          label="数量"
          width="210"
          align="center">
        </el-table-column>
        <el-table-column
          prop="sums"
          label="总价"
          width="210"
          align="center">
        </el-table-column>
        <el-table-column
          prop="id"
          label="药物编号"
          width="208"
          align="center">
        </el-table-column>
      </el-table-column>
    </el-table-column>
  </el-table>
  <el-pagination
    :current-page="currentPage"
    :total="total"
    :page-sizes="[5, 10, 15]"
    :page-size="pageSize"
    background
    layout="prev, pager, next, sizes, total, jumper"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
  </div>
</template>

<script>
  import {selectorder} from "../../api";

  export default {
    data() {
      return {
        tableData: [],
        dataList:[],
        currentPage: 1, //当前页
        pageSize: 5, //每页行数
        total: 0,
      }
    },
    methods:{
      look()
      {
        selectorder({uid:window.localStorage.getItem('id')}).
          then((res=>{
          this.tableData=res.data.data
          this.dataList = res.data.data;
          this.total = res.data.data.length;
          this.handleCurrentChange(1);
        }))
      },

      handleSizeChange: function (pageSize) {
        this.pageSize = pageSize;
        this.handleCurrentChange(this.currentPage);
        this.handleCurrentChange(1);
      },
      //页码切换
      handleCurrentChange: function (currentPage) {
        this.currentPage = currentPage;
        this.currentChangePage(this.dataList, currentPage);
      },
      //分页方法
      currentChangePage(list, currentPage) {
        let from = (currentPage - 1) * this.pageSize;
        let to = currentPage * this.pageSize;
        this.tableData = [];
        for (; from < to; from++) {
          if (list[from]) {
            this.tableData.push(list[from]);
          }
        }
      }
    },

    created() {
      this.look()
    }
  }
</script>
